
*By Kato
*IFPRI Washington DC. 2017
*Notes:   
    *There  two rounds of survey. The first round covered 1300 hhds, the second round only recovered 829 hhds, therefore attrition was 479 households. 


*use "D:\Kato\CGIAR_ISFM_Study\GeoPoll_Survey\EndlineData\Data\Endline_BaselineCombined\GeoPoll_Rwanda_Round 1&2 All Data_V2.dta",clear 
use "D:\Kato\Rwanda\GeopollSurvey_ISFMStudy\Data\Geopoll_ISFM_Survey\EndlineData\Data\Endline_BaselineCombined\GeoPoll_Rwanda_Round 1&2 All Data_V2.dta",clear 

rename  Round_Participated_In   attrition

gen round=1     if attrition=="Round 1"
replace round=2 if attrition=="Round 1 and 2"
label define roundlbl 1"round1only" 2"round1&2only"
label values round roundlbl


gen femrespond=1     if Gender=="Female"
replace femrespond=0 if Gender=="Male"


gen age_15_35=1   if Age_Group=="15-34"
gen age_35_54=1   if Age_Group=="35-54"
gen age_above54=1 if Age_Group=="55+"
for var age_15_35 age_35_54 age_above54:replace X=0 if X==.

gen creditformal=1     if FormalCreditServices=="Yes"
replace creditformal=0 if FormalCreditServices=="No"

gen creditnonformal=1     if  InformalCreditServices=="Yes"
replace creditnonformal=0 if  InformalCreditServices=="No"


gen growbeans=1         if  CropsPlanted_Dry_beans_x=="Yes"
replace growbeans=0 if  CropsPlanted_Dry_beans_x=="No"

gen growmaize=1         if   CropsPlanted_Maize_x=="Yes"
replace growmaize=0     if   CropsPlanted_Maize_x=="No"

gen growcassava=1         if   CropsPlanted_Cassava_x=="Yes"
replace growcassava=0     if   CropsPlanted_Cassava_x=="No"

gen growpotato=1         if   CropsPlanted_Potatoes=="Yes"
replace growpotato=0     if   CropsPlanted_Potatoes=="No"

gen growplantain=1         if   CropsPlanted_Plantain_x=="Yes"
replace growplantain=0     if   CropsPlanted_Plantain_x=="No"




*Compare Attritors and Non-Attritors 
*=============================================================
ttest Age, by(attrition)
median Age, by(attrition)
ttest age_15_35, by(attrition)
ttest age_35_54, by(attrition)
ttest age_above54, by(attrition)
ttest femrespond, by(attrition)
ttest growbeans, by(attrition)
ttest growmaize, by(attrition)
ttest growcassava, by(attrition)
ttest growpotato, by(attrition)



*sample sizes for Round1 and Round2 of the Geopoll SMS Survey
tab round
tab Province round
tab Age_Group round
tab Gender round

gen district_new="Rusizi"    if District=="Rusizi" |District=="Rusizi" | District=="Akarere Ka Rusizi"
replace district_new="Huye"      if District=="Huye" | District=="Akarere Ka Huye"
replace district_new="Nyagatare" if District=="Nyagatare" | District=="Nyagare"|District=="Nyamagabe Ariko Ubu Ndi Kwiga Nyagatare"
replace district_new="Gagenke"   if District=="Gakenke" | District=="Gakenye" | District=="Akarere Ka Gakenke" 
replace district_new="Musanze"   if District=="Musanze" | District=="Musanzd" | District=="Musanse" | District=="Akarere Ka Musanze"
replace district_new="Kayonza"   if District=="Kayonza" 
replace district_new="Kamonyi"   if District=="Kamonyi"
replace district_new="Burera"    if District=="Burera"
replace district_new="Bugesera"  if District=="Bugesera"
replace district_new="otherdistrict"     if district_new==""



gen treatment_ISFM=1     if district_new=="Kayonza" | district_new=="Musanze" | district_new=="Gagenke" |district_new=="Kamonyi" | district_new=="Burera" | district_new=="Bugesera" 
replace treatment_ISFM=0 if district_new=="Rusizi" | district_new=="Huye" | district_new=="Nyagatare" | district_new=="otherdistrict" 

tab district_new round
tab district_new Gender,row
tab treatment_ISFM  round
tab Gender round, row



gen original_sampletreatment=1 if  district_new=="Kayonza" | district_new=="Musanze" | district_new=="Gagenke"
replace original_sampletreatment=0   if district_new=="Rusizi" | district_new=="Huye" | district_new=="Nyagatare"



*Compare Attritors and Non-Attritors (Entire Sample: in Sample and Out-Sample Observations ) 
*In-sample: The original selected treated and control districts. Out-sample additional districts included in the survey
*==========================================================================================================================

*all sample (both in-sample and Out-Sample)
ttest Age, by(attrition)
median Age, by(attrition)
ttest age_15_35, by(attrition)
ttest age_35_54, by(attrition)
ttest age_above54, by(attrition)
ttest femrespond, by(attrition)
ttest growbeans, by(attrition)
ttest growmaize, by(attrition)
ttest growcassava, by(attrition)
ttest growpotato, by(attrition)



*Testing Attrition based In-sample sample observations
ttest Age          if original_sampletreatment~=., by(attrition)
median Age         if original_sampletreatment~=., by(attrition)
ttest age_15_35    if original_sampletreatment~=., by(attrition)
ttest age_35_54    if original_sampletreatment~=., by(attrition)
ttest age_above54  if original_sampletreatment~=., by(attrition)
ttest femrespond   if original_sampletreatment~=., by(attrition)
ttest growbeans    if original_sampletreatment~=., by(attrition)
ttest growmaize    if original_sampletreatment~=., by(attrition)
ttest growcassava  if original_sampletreatment~=., by(attrition)
ttest growpotato   if original_sampletreatment~=., by(attrition)


*Testing Attrition based on  out of-sample observations
ttest Age          if original_sampletreatment==., by(attrition)
median Age         if original_sampletreatment==., by(attrition)
ttest age_15_35    if original_sampletreatment==., by(attrition)
ttest age_35_54    if original_sampletreatment~=., by(attrition)
ttest age_above54  if original_sampletreatment==., by(attrition)
ttest femrespond   if original_sampletreatment==., by(attrition)
ttest growbeans    if original_sampletreatment==., by(attrition)
ttest growmaize    if original_sampletreatment==., by(attrition)
ttest growcassava  if original_sampletreatment==., by(attrition)
ttest growpotato   if original_sampletreatment==., by(attrition)






tabstat creditformal,    by(round) stats(mean n)
tabstat creditnonformal, by(round) stats(mean n)

destring AbleBodyFemale AbleBodyMale, replace force
tabstat AbleBodyFemale AbleBodyMale,by(round) stats(mean sd n)

destring Distance, replace force
tabstat Distance if Distance<60,by(round) stats(mean median sd n)

*use improved seeds in beans
destring DryBeansHarvested,replace force
gen beancertified=1 if VarietiesBean_Certified_improved=="Yes"
gen beanimpvrecycled=1  if VarietiesBean_Recycled_improved =="Yes"  // improved recycled //
for var beancertified beanimpvrecycled: replace X=0 if X==. & DryBeansHarvested~=.
tabstat beancertified beanimpvrecycled, by(round) stats(mean sd n)

*use improved seeds in maize:
destring MaizeHarvested,replace force
gen mzcertified=1     if VarietiesMaize_Certified_improve=="Yes"
gen mzimpvrecycled=1  if VarietiesMaize_Recycled_improved=="Yes"  // improved recycled //
for var mzcertified mzimpvrecycled: replace X=0 if X==. & MaizeHarvested~=.
tabstat mzcertified mzimpvrecycled, by(round) stats(mean sd n)



*use manure, fertilizer, ISFM in beans
gen usemanurebean=1 if SoilFertilityBeans_Manure_Compos=="Yes"
replace  usemanurebean=0 if SoilFertilityBeans_Manure_Compos=="No" 


destring QuantityFertilizerBean,replace force
gen usefertbean=1      if QuantityFertilizerBean~=. & QuantityFertilizerBean~=0
replace usefertbean=0  if usefertbean==. & growbeans==1

gen useagroforestbean=1 if  SoilFertilityBeans_Agroforestry=="Yes"
replace  useagroforestbean=0 if  SoilFertilityBeans_Agroforestry=="No" 

gen usecropresidbean=1       if  SoilFertilityBeans_Crop_residues=="Yes"
replace  usecropresidbean=0  if  SoilFertilityBeans_Crop_residues=="No" 

gen usemulchbean=1       if  SoilFertilityBeans_Mulching=="Yes"
replace  usemulchbean=0  if  SoilFertilityBeans_Mulching=="No" 

gen useisfmbean=1 if (usefertbean==1  & (usemanurebean==1 | usecropresidbean==1 | usemulchbean==1 | useagroforestbean==1))
replace useisfmbean=0 if useisfmbean==. & growbeans==1

for var usemanurebean usefertbean useagroforestbean usecropresidbean usemulchbean useisfmbean: replace X=0 if X==. & growbean==1
tabstat usemanurebean usefertbean useagroforestbean usecropresidbean usemulchbean useisfmbean, by(attrition) stats(mean n)






*use manure, fertilizer, ISFM in Maize
gen usemanuremaize=1 if SoilFertilityMaize_Manure_Compos=="Yes"
replace  usemanuremaize=0 if SoilFertilityMaize_Manure_Compos=="No" 


destring QuantityFertilizerMaize,replace force
gen usefertmaize=1      if QuantityFertilizerMaize~=. & QuantityFertilizerMaize~=0
replace usefertmaize=0  if usefertmaize==. & growmaize==1

gen useagroforestmaize=1 if  SoilFertilityMaize_Agroforestry=="Yes"
replace  useagroforestmaize=0 if  SoilFertilityMaize_Agroforestry=="No" 

gen usecropresidmaize=1       if  SoilFertilityMaize_Crop_residues=="Yes"
replace  usecropresidmaize=0  if  SoilFertilityMaize_Crop_residues=="No" 

gen usemulchmaize=1       if  SoilFertilityMaize_Mulching=="Yes"
replace  usemulchmaize=0  if  SoilFertilityMaize_Mulching=="No" 

gen useisfmmaize=1 if (usefertmaize==1  & (usemanuremaize==1 | usecropresidmaize==1 | usemulchmaize==1 | useagroforestmaize==1))
replace useisfmmaize=0 if useisfmmaize==. & growmaize==1

for var usemanuremaize usefertmaize useagroforestmaize usecropresidmaize usemulchmaize useisfmmaize: replace X=0 if X==. & growmaize==1
tabstat usemanuremaize usefertmaize useagroforestmaize usecropresidmaize usemulchmaize useisfmmaize, by(attrition) stats(mean n)


tabstat usemanuremaize usefertmaize useagroforestmaize usecropresidmaize usemulchmaize useisfmmaize if growmaize==1, by(attrition) stats(mean n)




*Fertilizer quantity used in Maize:
destring FertilizersMaize  QuantityFertilizerMaize,replace force





*use manure, fertilizer, ISFM in Plantains.
gen usemanureplantain=1 if SoilFertilityPlantains_Manure_Co=="Yes"
replace  usemanureplantain=0 if SoilFertilityPlantains_Manure_Co=="No" 

gen usefertplantain=1      if FertilizersPlantains=="Yes"
replace usefertplantain=0  if FertilizersPlantains=="No"


gen useagroforestplantain=1 if  SoilFertilityPlantains_Agrofores=="Yes"
replace  useagroforestplantain=0 if  SoilFertilityPlantains_Agrofores=="No" 

gen usecropresidplantain=1       if  SoilFertilityPlantains_Crop_resi=="Yes"
replace  usecropresidplantain=0  if  SoilFertilityPlantains_Crop_resi=="No" 

gen usemulchplantain=1       if  SoilFertilityPlantains_Mulching=="Yes"
replace  usemulchplantain=0  if  SoilFertilityPlantains_Mulching=="No" 

gen useisfmplantain=1 if (usefertplantain==1  & (usemanureplantain==1 | usecropresidplantain==1 | usemulchplantain==1 | useagroforestplantain==1))
replace useisfmplantain=0 if useisfmplantain==. & growplantain==1

for var usemanureplantain usefertplantain useagroforestplantain usecropresidplantain usemulchplantain useisfmplantain: replace X=0 if X==. & growplantain==1
tabstat usemanureplantain usefertplantain useagroforestplantain usecropresidplantain usemulchplantain useisfmplantain, by(attrition) stats(mean n)





*use manure, fertilizer, ISFM in Cassava.
gen usemanurecassava=1       if SoilFertilityCassava_Manure_Comp=="Yes"
replace  usemanurecassava=0 if SoilFertilityCassava_Manure_Comp=="No" 

gen usefertcassava=1      if FertilizersCassava=="Yes"
replace usefertcassava=0  if FertilizersCassava=="No"


gen useagroforestcassava=1      if   SoilFertilityCassava_Agroforestr=="Yes"
replace  useagroforestcassava=0 if   SoilFertilityCassava_Agroforestr=="No" 

gen usecropresidcassava=1       if  SoilFertilityCassava_Crop_residu=="Yes"
replace  usecropresidcassava=0  if  SoilFertilityCassava_Crop_residu=="No" 

gen usemulchcassava=1       if  SoilFertilityCassava_Mulching=="Yes"
replace  usemulchcassava=0  if  SoilFertilityCassava_Mulching=="No" 

gen useisfmcassava=1 if (usefertcassava==1  & (usemanurecassava==1 | usecropresidcassava==1 | usemulchcassava==1 | useagroforestcassava==1))
replace useisfmcassava=0 if useisfmcassava==. & growcassava==1

for var usemanurecassava usefertcassava useagroforestcassava usecropresidcassava usemulchcassava useisfmcassava: replace X=0 if X==. & growcassava==1
tabstat usemanurecassava usefertcassava useagroforestcassava usecropresidcassava usemulchcassava useisfmcassava, by(attrition) stats(mean n)







*use manure, fertilizer, ISFM in Potatoes.
gen usemanurepotato=1       if  SoilFertilityPotatoes_Manure_Com=="Yes"
replace  usemanurepotato=0  if  SoilFertilityPotatoes_Manure_Com=="No" 

gen usefertpotato=1      if FertilizersPotatoes=="Yes"
replace usefertpotato=0  if FertilizersPotatoes=="No"


gen useagroforestpotato=1      if   SoilFertilityPotatoes_Agroforest=="Yes"
replace  useagroforestpotato=0 if   SoilFertilityPotatoes_Agroforest=="No" 

gen usecropresidpotato=1       if  SoilFertilityPotatoes_Crop_resid=="Yes"
replace  usecropresidpotato=0  if  SoilFertilityPotatoes_Crop_resid=="No" 

gen usemulchpotato=1       if  SoilFertilityPotatoes_Mulching=="Yes"
replace  usemulchpotato=0  if  SoilFertilityPotatoes_Mulching=="No" 

gen useisfmpotato=1 if (usefertpotato==1  & (usemanurepotato==1 | usecropresidpotato==1 | usemulchpotato==1 | useagroforestpotato==1))
replace useisfmpotato=0 if useisfmpotato==. & growpotato==1

for var usemanurepotato usefertpotato  useagroforestpotato usecropresidpotato usemulchpotato useisfmpotato: replace X=0 if X==. & growpotato==1
tabstat usemanurepotato usefertpotato  useagroforestpotato usecropresidpotato usemulchpotato useisfmpotato, by(attrition) stats(mean n)





*Total crop area:
*TotalCropArea











*Maize Yields:
*==========================

destring MaizeHarvested MaizeSize, replace force


replace MaizeSize=MaizeSize/10 if MaizeSize>100  // data cleaning //
replace MaizeHarvested=MaizeHarvested/100 if MaizeHarvested>10000

gen mzyield= MaizeHarvested/ MaizeSize        // maizeSize is area in acres //
tabstat mzyield MaizeSize  if mzyield<5000  & MaizeSize<110 , stats(mean median sd n)

tabstat mzyield  MaizeSize if mzyield<5000  & MaizeSize<110 & attrition=="Round 1 and 2", stats(mean median sd n)  // non-attriting sample because yields were measured in round2 //





*maize yields by ISFM treatment and control districts
tabstat mzyield  if mzyield<5000  & MaizeSize<110 , stats(mean median sd n max) by(treatment_ISFM)  // non-attriting sample because yields were measured in round2 //

tabstat mzyield  if mzyield<3000 &  mzyield>0.16,by(treatment_ISFM) stats(mean median sd n max)

* assesse weakness in data 
egen meanmaize=mean(mzyield) if mzyield~=. & mzyield<3000 &  mzyield>0.16
egen sdmaize=sd(mzyield)     if mzyield~=. & mzyield<3000 &  mzyield>0.16
gen ciposmz2=mean+(2*sdmaize)
gen ciposmz3=mean+(3*sdmaize)
sum ciposmz2 if (mzyield>ciposmz2 ) & mzyield~=.
sum ciposmz2 if (mzyield>ciposmz3 ) & mzyield~=.

tabstat ciposmz2 if (mzyield>ciposmz2 ) & mzyield~=., by(treatment_ISFM) stats(n)
tabstat ciposmz2 if (mzyield>ciposmz3 ) & mzyield~=., by(treatment_ISFM) stats(n)

ttest mzyield if mzyield<3000 &  mzyield>0.16, by(treatment_ISFM)
median mzyield if mzyield<3000 &  mzyield>0.16, by(treatment_ISFM)



destring MaizeSize DryBeansSize SizePlantains SizePotatoes,replace force
tabstat  MaizeSize DryBeansSize SizePlantains SizePotatoes, stats(mean median sd n min max p25  p50 p75 p90)








*Share of maize sold: 
*==========================
destring MaizeSize MaizeHarvested MaizeSold, replace force
gen sharesoldmz= MaizeSold/ MaizeHarvested
replace sharesoldmz=0 if sharesoldmz==. & MaizeHarvested~=0

tabstat sharesoldmz mzyield  MaizeSize if mzyield<5000  & MaizeSize<110 & attrition=="Round 1 and 2", stats(mean median sd n)  // non-attriting sample because yields were measured in round2 //
tabstat sharesoldmz mzyield  MaizeSize if sharesoldmz<1.0 & mzyield<5000  & MaizeSize<110 & attrition=="Round 1 and 2", stats(mean median sd n)  // non-attriting sample because yields were measured in round2 //


tabstat sharesoldmz mzyield  MaizeSize if sharesoldmz<1.0 & mzyield<5000  & MaizeSize<110 , stats(mean median sd n) by(attrition) // non-attriting sample because yields were measured in round2 //
tabstat sharesoldmz mzyield  MaizeSize if sharesoldmz<1.0 & mzyield<5000  & MaizeSize<110 , stats(mean median sd n) by(round) // non-attriting sample because yields were measured in round2 //






*Bean Yields:
*==========================

destring  DryBeansSize DryBeansHarvested DryBeansSold, replace force
gen beanyield= DryBeansHarvested/ DryBeansSize
tabstat beanyield DryBeansSize  if beanyield<5000  & DryBeansSize<110 , stats(mean median sd n)

tabstat beanyield  DryBeansSize if beanyield<5000  & DryBeansSize<110 & attrition=="Round 1 and 2", stats(mean median sd n)  // non-attriting sample because yields were measured in round2 //








*Bean yields by ISFM treatment and control districts
tabstat beanyield  if beanyield<5000  & DryBeansSize<110 , stats(mean median sd n max) by(treatment_ISFM)  // non-attriting sample because yields were measured in round2 //




* assesse weakness in data 
egen meanbean=mean(beanyield) if beanyield<5000  & DryBeansSize<110
egen sdbean=sd(beanyield)   if beanyield<5000  & DryBeansSize<110 
gen ciposbe2=meanbean+(2*sdbean)
gen ciposbe3=meanbean+(3*sdbean)
sum ciposbe2 if (beanyield>ciposmz2 ) & beanyield~=.
sum ciposbe2 if (beanyield>ciposmz3 ) & beanyield~=.

tabstat ciposbe2 if (beanyield>ciposmz2 ) & beanyield~=., by(treatment_ISFM) stats(n)
tabstat ciposbe2 if (beanyield>ciposmz3 ) & beanyield~=., by(treatment_ISFM) stats(n)

ttest beanyield if beanyield<5000  & DryBeansSize<110, by(treatment_ISFM)
median beanyield if beanyield<5000  & DryBeansSize<110, by(treatment_ISFM)











*Share of Bean sold: 
*==========================
destring  DryBeansSize DryBeansHarvested DryBeansSold, replace force
gen sharesoldbean= DryBeansSold/ DryBeansHarvested
replace sharesoldbean=0 if sharesoldbean==. & DryBeansHarvested~=0

tabstat sharesoldbean beanyield  DryBeansSize if beanyield<5000  & DryBeansSize<110 & attrition=="Round 1 and 2", stats(mean median sd n)  // non-attriting sample only because yields were measured in round2 //
tabstat sharesoldbean beanyield  DryBeansSize if sharesoldbean<1.0 & beanyield<5000  & DryBeansSize<110 & attrition=="Round 1 and 2", stats(mean median sd n)  // non-attriting sample only because yields were measured in round2 //


tabstat sharesoldbean beanyield  DryBeansSize if  beanyield<5000  & DryBeansSize<110 , stats(mean median sd n) by (round)
tabstat sharesoldbean beanyield  DryBeansSize if sharesoldbean<1.0 & beanyield<5000  & DryBeansSize<110 , stats(mean median sd n) by(round)


tabstat sharesoldbean beanyield  DryBeansSize if  beanyield<5000  & DryBeansSize<110 , stats(mean median sd n) by (attrition)
tabstat sharesoldbean beanyield  DryBeansSize if sharesoldbean<1.0 & beanyield<5000  & DryBeansSize<110 , stats(mean median sd n) by(attrition)









*Maize Yeilds Functions: without SLM
*===========================================
for var mzyield AbleBodyFemale AbleBodyMale MaizeSize: gen lnX=ln(X+1)
regress lnmzyield lnMaizeSize creditformal creditnonformal femrespond mzcertified mzimpvrecycled lnAbleBodyFemale lnAbleBodyMale if mzyield<5000  & MaizeSize<110
xi:regress lnmzyield lnMaizeSize creditformal creditnonformal femrespond mzcertified mzimpvrecycled lnAbleBodyFemale lnAbleBodyMale i.District if mzyield<5000  & MaizeSize<110
xi:regress lnmzyield lnMaizeSize creditformal creditnonformal femrespond mzcertified mzimpvrecycled lnAbleBodyFemale lnAbleBodyMale i.Province if mzyield<5000  & MaizeSize<110


*Maize Yeilds Functions: with SLM
*========================================

gen useorganicmaize=1 if usemanuremaize==1|useagroforestmaize==1| usecropresidmaize==1| usemulchmaize==1

for var usemanuremaize usefertmaize useagroforestmaize usecropresidmaize usemulchmaize useisfmmaize useorganicmaize:replace X=0 if X==.

global maizeslm="usemanuremaize usefertmaize useagroforestmaize usecropresidmaize usemulchmaize useisfmmaize useorganicmaize"



regress lnmzyield $maizeslm lnMaizeSize creditformal creditnonformal femrespond mzcertified mzimpvrecycled lnAbleBodyFemale lnAbleBodyMale 


regress lnmzyield usemanuremaize usefertmaize useagroforestmaize usecropresidmaize usemulchmaize useisfmmaize useorganicmaize
regress lnmzyield  usefertmaize  useisfmmaize useorganicmaize lnMaizeSize creditformal creditnonformal femrespond mzcertified mzimpvrecycled lnAbleBodyFemale lnAbleBodyMale 



*Maize Yields by treatments of SLM
*===================================================
gen slmgroupmaize=1     if useisfmmaize==1 
replace slmgroupmaize=2 if useisfmmaize==0 & usefertmaize==1 & useorganicmaize==0
replace slmgroupmaize=3 if (useisfmmaize==0 & usefertmaize==0 & useorganicmaize==1)
replace slmgroupmaize=4 if (useisfmmaize==0 & usefertmaize==0 & useorganicmaize==0)
label  define slmgroupmaizelbl 1"isfm" 2"fertonly" 3"organiconly" 4"noinputs"
label values slmgroupmaize slmgroupmaizelbl


oneway mzyield slmgroupmaize if mzyield<5000  & MaizeSize<110,sidak tab

bys femrespond: oneway mzyield slmgroupmaize if mzyield<5000 & MaizeSize<110 ,sidak tab


tabstat  mzyield  if mzyield<5000  & MaizeSize<110,by(slmgroupmaize) stats(mean median sd n)

tabstat  mzyield  if mzyield>10 & mzyield<1000  & MaizeSize<100,by(slmgroupmaize) stats(mean median sd n)

tabstat  mzyield  if mzyield>10 & mzyield<600  ,by(slmgroupmaize) stats(mean median sd n)

tabstat  mzyield  if mzyield>0.8 & mzyield<1000  ,by(slmgroupmaize) stats (mean median sd n)


tabstat mzyield  if mzyield<3000 &  mzyield>0.16,by(slmgroupmaize) stats(mean median  sd n)
bys femrespond:tabstat mzyield  if mzyield<3000 &  mzyield>0.16,by(slmgroupmaize) stats(mean median  sd n)



tab  slmgroupmaize round if  mzyield~=.,col
tab  Province slmgroupmaize if  mzyield~=.,row
tab  Age_Group slmgroupmaize if  mzyield~=.
tab  Gender slmgroupmaize if  mzyield~=.




tabstat mzyield  if mzyield<3000 &  mzyield>0.16,by(treatment_ISFM) stats(mean median  sd n)	
	
	
	
	
	
	
			
*Maize Quantity of Fertilizer by treatments of SLM
*=============================================================
gen maizeqtyfertha=QuantityFertilizerMaize/MaizeSize if QuantityFertilizerMaize~=0

tabstat maizeqtyfertha  if mzyield<5000  & MaizeSize<110,by(slmgroupmaize) stats(mean median sd)








*Bean Yields Functions: without SLM 
*====================================================
for var beanyield  DryBeansSize: gen lnX=ln(X+1)
regress lnbeanyield lnDryBeansSize  creditformal creditnonformal femrespond beancertified beanimpvrecycled lnAbleBodyFemale lnAbleBodyMale if beanyield<5000  & DryBeansSize<110
xi:regress lnbeanyield lnDryBeansSize usemanurebean creditformal creditnonformal femrespond beancertified beanimpvrecycled lnAbleBodyFemale lnAbleBodyMale i.District if beanyield<5000  & DryBeansSize<110
xi:regress lnbeanyield lnDryBeansSize usemanurebean creditformal creditnonformal femrespond beancertified beanimpvrecycled lnAbleBodyFemale lnAbleBodyMale i.Province if beanyield<5000  & DryBeansSize<110




*Bean Yeilds Functions: with SLM 
global beanslm="usemanurebean usefertbean useagroforestbean usecropresidbean usemulchbean useisfmbean"
regress lnbeanyield lnDryBeansSize $beanslm creditformal creditnonformal femrespond beancertified beanimpvrecycled lnAbleBodyFemale lnAbleBodyMale if beanyield<5000  & DryBeansSize<110
xi:regress lnbeanyield lnDryBeansSize $beanslm usemanurebean creditformal creditnonformal femrespond beancertified beanimpvrecycled lnAbleBodyFemale lnAbleBodyMale i.District if beanyield<5000  & DryBeansSize<110
xi:regress lnbeanyield lnDryBeansSize $beanslm usemanurebean creditformal creditnonformal femrespond beancertified beanimpvrecycled lnAbleBodyFemale lnAbleBodyMale i.Province if beanyield<5000  & DryBeansSize<110

regress lnbeanyield lnDryBeansSize useisfmbean creditformal creditnonformal femrespond beancertified beanimpvrecycled lnAbleBodyFemale lnAbleBodyMale if beanyield<5000  & DryBeansSize<110
xi:regress lnbeanyield lnDryBeansSize useisfmbean usemanurebean creditformal creditnonformal femrespond beancertified beanimpvrecycled lnAbleBodyFemale lnAbleBodyMale i.District if beanyield<5000  & DryBeansSize<110
xi:regress lnbeanyield lnDryBeansSize useisfmbean usemanurebean creditformal creditnonformal femrespond beancertified beanimpvrecycled lnAbleBodyFemale lnAbleBodyMale i.Province if beanyield<5000  & DryBeansSize<110


sum  lnbeanyield lnDryBeansSize useisfmbean creditformal creditnonformal femrespond beancertified beanimpvrecycled lnAbleBodyFemale lnAbleBodyMale if beanyield<5000  & DryBeansSize<110



gen useorganicbean=1 if usemanurebean==1|useagroforestbean==1| usecropresidbean==1| usemulchbean==1
replace useorganicbean=0 if useorganicbean==.



gen slmgroupbean=1     if useisfmbean==1 
replace slmgroupbean=2 if useisfmbean==0 & usefertbean==1 & useorganicbean==0
replace slmgroupbean=3 if (useisfmbean==0 & usefertbean==0 & useorganicbean==1)
replace slmgroupbean=4 if (useisfmbean==0 & usefertbean==0 & useorganicbean==0)
label  define slmgroupbeanlbl 1"isfm" 2"fertonly" 3"organiconly" 4"noinputs"
label values slmgroupbean slmgroupbeanlbl


oneway mzyield slmgroupbean if beanyield<5000  & DryBeansSize<110,sidak tab

bys femrespond: oneway beanyield slmgroupbean if beanyield<5000 & DryBeansSize<110 ,sidak tab




save "D:\Kato\Rwanda\GeopollSurvey_ISFMStudy\Data\Geopoll_ISFM_Survey\EndlineData\Data\Endline_BaselineCombined\GeoPollSurvey_MultivariateKatoCreatedVariables.dta",clear












*USING LSMS Data That is Nationally Representative: 
*(To Compare Above Geopoll SMS survey with Nsationally Representative Data
*======================================================================================================================================
*=======================================================================================================================================



use "D:\Kato\Rwanda\GeopollSurvey_ISFMStudy\Data\LSMS_Data\Data\Rwanda ag survey 2013\rsas-2013-data-stata-Season A\1_Identifiant_A_Small_Scale_Farmer.dta",clear 

ren ID1 province
ren ID2A district
ren I15 memcooperative
gen femhhd=1     if I07==2
replace femhhd=0 if I07==1
ren I08 agefarmer

gen age15_35=1 if agefarmer>14 & agefarmer<35
gen age35_54=1 if agefarmer>14 & agefarmer<55
gen ageabove54=1 if agefarmer>54
for var age15_35 age35_54 ageabove54:replace X=0 if X==.

keep IDQUEST province district femhhd agefarmer Age_group age15_35 age35_54 ageabove54
sort IDQUEST
save tempa,replace 




use "D:\Kato\Rwanda\GeopollSurvey_ISFMStudy\Data\LSMS_Data\Data\Rwanda ag survey 2013\rsas-2013-data-stata-Season A\03_Area_Season_A.dta",clear
egen maizearea_seasonA=sum(Area_Ha)       if CROP_CODE==1, by(IDQUEST)
egen beanarea_seasonA=sum(Area_Ha)        if CROP_CODE==6 | CROP_CODE==7, by(IDQUEST)
egen cassavaarea_seasonA=sum(Area_Ha)     if CROP_CODE==10, by(IDQUEST)
egen spotatoaarea_seasonA=sum(Area_Ha)    if CROP_CODE==12, by(IDQUEST)
egen ipotatoaarea_seasonA=sum(Area_Ha)    if CROP_CODE==11, by(IDQUEST)
egen cbananaaarea_seasonA=sum(Area_Ha)    if CROP_CODE==21, by(IDQUEST)  // cooking banana //
egen bbananaaarea_seasonA=sum(Area_Ha)    if CROP_CODE==21, by(IDQUEST)  // beer banana //
collapse maizearea_seasonA beanarea_seasonA cassavaarea_seasonA spotatoaarea_seasonA ipotatoaarea_seasonA cbananaaarea_seasonA bbananaaarea_seasonA,by(IDQUEST)
for var maizearea_seasonA beanarea_seasonA cassavaarea_seasonA spotatoaarea_seasonA ipotatoaarea_seasonA cbananaaarea_seasonA bbananaaarea_seasonA: label variable " area i seasonA in ha"
sort  IDQUEST
merge  IDQUEST using tempa
tab _m
drop _m
sort  IDQUEST
save tempa,replace




use "D:\Kato\Rwanda\GeopollSurvey_ISFMStudy\Data\LSMS_Data\Data\Rwanda ag survey 2013\rsas-2013-data-stata-Season A\03_Big_Farmer_Season_A.dta",clear 












tabstat femhhd agefarmer, stats(mean n)

















